package com.xmtlxx.system.mapper;

import cn.hutool.core.collection.CollectionUtil;
import com.xmtlxx.common.annotation.DataColumn;
import com.xmtlxx.common.annotation.DataPermission;
import com.xmtlxx.common.core.mapper.BaseMapperPlus;
import com.xmtlxx.system.domain.SysOss;
import com.xmtlxx.system.domain.bo.SysOssBo;
import com.xmtlxx.system.domain.vo.SysOssVo;
import com.xmtlxx.system.enums.OssBuss;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;

import java.util.List;


/**
 * 文件上传 数据层
 *
 * @author xmtlxx
 */
public interface SysOssMapper extends BaseMapperPlus<SysOssMapper, SysOss, SysOssVo> {

    /**
     * update batch buss and objId by id
     *
     * @param ossList oss info list
     * @param ossBuss oss buss
     * @param objId   obj id
     * @author hergreen
     * @date 2024/08/02 11:41
     */
    default void updateBatchBussAndObjIdById(List<SysOss> ossList, OssBuss ossBuss, String objId) {

        if (CollectionUtil.isNotEmpty(ossList)) {
            ossList.forEach(oss -> {
                oss.setBuss(ossBuss.getValue());
                oss.setObjid(objId);
            });
            this.updateBatchById(ossList);
        }
    }

    /**
     * 根据条件分页查询OSS对象存储
     *
     * @param sysOss OSS对象存储
     * @return Page SysOss
     */
    @DataPermission({
            @DataColumn(key = "tenantName", value = "s.create_by"),
//        @DataColumn(key = "deptName", value = "u.dept_id"),
//        @DataColumn(key = "userName", value = "s.create_by")
    })
    Page<SysOss> selectPageSysOssList(@Param("page") Page<SysOss> page, @Param("sysOss") SysOssBo sysOss);

    /**
     * 查询OSS对象存储列表
     *
     * @param sysOss OSS对象存储
     * @return OSS对象存储集合
     */
    @DataPermission({
            @DataColumn(key = "tenantName", value = "s.create_by"),
//        @DataColumn(key = "deptName", value = "u.dept_id"),
//        @DataColumn(key = "userName", value = "s.create_by")
    })
    List<SysOss> selectSysOssList(@Param("sysOss") SysOssBo sysOss);

    List<SysOss> selectOssList(@Param("sysOss") SysOssBo sysOss);

    Page<SysOssVo> selectSysOssByHandoverList(@Param("page") Page<SysOss> page, @Param("sysOss") SysOssBo sysOss);

    List<SysOss> selectPropertySysOssList(@Param("sysOss") SysOssBo sysOss);

}
